<?php
if(isset($_SESSION['QuyenHan']) && $_SESSION['QuyenHan'] == 1)
{
	$phongban = new phongbanbs();
	if(isset($_POST['btnTim']))
	{
		$TenPhongBan = mb_convert_case($_POST['TenPhongBan'],MB_CASE_TITLE,"utf-8") ;
		$DienThoai = $_POST['DienThoai'];
		$MoTa = $_POST['MoTa'];
		$phongban->TenPhongBan = $TenPhongBan;
		$phongban->DienThoai = $DienThoai;
		$phongban->MoTa = $MoTa;	
	}
	$danhsach = $phongban->GetList();
	
?>

<div id="NoiDung" style="position:relative" class="form">
  <h3  class="text-primary">DANH MỤC PHÒNG BAN</h3>
  <div style="position:absolute; left:840px; top:10px;"><a href="phongban-them"><span class="glyphicon glyphicon-plus-sign" style="font-size:18px"></span></a> <a href="#"  style="margin-left:10px"><span id="clickSearch" class="glyphicon glyphicon-search" style="font-size:18px"></span></a></div>
  <div style="margin-top:20px; display:none" id="search">
    <form  action="phongban" method="post" role="form" class="form-inline">
      <div class="form-group form-custom">
        <label  for="tenphong">Tên phòng ban:</label>
        <input type="text" class="form-control" placeholder="Nhập tên phòng ban" name="TenPhongBan" class="required" />
      </div>
      <div class="form-group form-custom">
        <label  for="dienthoai">Điện thoại:</label>
        <input type="text" class="form-control" placeholder="Nhập số điện thoại" name="DienThoai" class="required" />
      </div>
      <div class="form-group form-custom">
        <label  for="mota">Mô tả:</label>
        <input type="text" class="form-control" placeholder="Mô tả" name="MoTa" class="required" />
      </div>
      <input type="submit" value="Tìm" class="btn btn-primary btn-primary" name="btnTim" />
    </form>
  </div>
  <script>
 $("#clickSearch").click(function()
	{
		$("#search").toggle("fast");
})

 </script> 
  <!--Bang phong ban-->
  
  <div style="margin-top:20px;">
    <table class="table table-hover table-bordered table-striped">
      <thead>
        <tr>
          <th  style="text-align:center"> STT </th>
          <th style="text-align:center"> Tên phòng ban </th>
           <th style="text-align:center"> Điện thoại</th>
          <th style="text-align:center"> Mô tả </th>
          <th style="text-align:center"> Sửa </th>
          <th style="text-align:center"> Xóa </th>
        </tr>
      </thead>
      <tbody>
        <?php
		
	if(!is_null($danhsach[0]['MaPhongBan']))
	{
		
				for($i = 0; $i < count($danhsach); $i++)
				{
					$stt=$i+1;
					echo "<tr>";
						echo "<td>{$danhsach[$i]['MaPhongBan']}</td>";
						if(isset($_POST['TenPhongBan']))
						echo "<td>".highlight($danhsach[$i]['TenPhongBan'],$TenPhongBan)."</td>";
						else
						echo "<td>{$danhsach[$i]['TenPhongBan']}</td>";
						if(isset($_POST['DienThoai']))
						echo "<td>".highlight($danhsach[$i]['DienThoai'],$DienThoai)."</td>";
						else
						echo "<td>{$danhsach[$i]['DienThoai']}</td>";
						if(isset($_POST['MoTa']))
						echo "<td>".highlight($danhsach[$i]['MoTa'],$MoTa)."</td>";
						else
						echo "<td>{$danhsach[$i]['MoTa']}</td>";
						
						
						echo "<td align='center'><a href='phongban-sua_" . $danhsach[$i]['MaPhongBan'] . "'><span class='glyphicon glyphicon-pencil'></span></a></td>";
						
						echo "<td align='center'><a href='phongban-xoa_" . $danhsach[$i]['MaPhongBan'] . "' onclick='return confirm(\"Bạn có muốn xóa " . $danhsach[$i]['TenPhongBan'] . " không?\")'><span class='glyphicon glyphicon-trash'></span></a></td>";
					echo "</tr>";
				}
	}
			?>
      </tbody>
    </table>
  </div>
</div>

<?php
}else
{
	ThongBaoLoi("Vui lòng đăng nhập !");
}
?>